package com.zhou.service;

import com.zhou.dao.SchoolStudentMessageDAO;
import com.zhou.dao.StudentDAO;
import com.zhou.entity.SchoolStudentMessage;
import com.zhou.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.Period;
import java.util.List;

@Service("schoolStudentMessageService")
public class SchoolStudentMessageServiceImpl implements SchoolStudentMessageService {
    @Autowired
    private SchoolStudentMessageDAO schoolStudentMessageDAO;
    @Autowired
    private StudentDAO studentDAO;

    @Override
    public List<SchoolStudentMessage> findTask(Long StudentID) {
        Integer year = studentDAO.findyear(StudentID);
        String Grade = "";
        //现在的时间
        LocalDate today = LocalDate.now();
        //指定的时间
        // 参数为整数型
        LocalDate oldDate = LocalDate.of(year, 9, 1);

        Period p = Period.between(oldDate, today);
        switch (p.getYears()){
            case 0:
                Grade="大一";
                break;
            case 1:
                Grade="大二";
                break;
            case 2:
                Grade="大三";
                break;
            case 3:
                Grade="大四";
                break;
        }
        if (p.getYears()>=4){
            Grade="已经毕业";
        }
        return schoolStudentMessageDAO.findTask(StudentID,Grade);
    }

    @Override
    public List<SchoolStudentMessage> findNotice(Long StudentID) {
        Integer year = studentDAO.findyear(StudentID);
        String Grade = "";
        //现在的时间
        LocalDate today = LocalDate.now();
        //指定的时间
        // 参数为整数型
        LocalDate oldDate = LocalDate.of(year, 9, 1);

        Period p = Period.between(oldDate, today);
        switch (p.getYears()){
            case 0:
                Grade="大一";
                break;
            case 1:
                Grade="大二";
                break;
            case 2:
                Grade="大三";
                break;
            case 3:
                Grade="大四";
                break;
        }
        if (p.getYears()>=4){
            Grade="已经毕业";
        }
        return schoolStudentMessageDAO.findNotice(StudentID,Grade);
    }
}
